<?
	//define('IN_SITE', true);
	require_once("class/functions.php") ;
	$ids = isset($_REQUEST['ids'])? $_REQUEST['ids'] : session_id() ;
	$lng = isset($_REQUEST['lang'])? $_REQUEST['lang'] : 'us' ;
		
	$url=$_SERVER['HTTP_HOST'].$_SERVER['QUERY_STRING']; 
	if (eregi("main.php",$url)) {	
		die("&nbsp;");
	}
	//check_gpc();
	 
	$template_main_page="template/main.tpl";
	$template_sub_cat="template/subcat.tpl";
	$base_url 	= 'index.php';	 
	
	$url= substr($url,strpos($url,".php"),strlen($url));
	$url=explode("/",$url);
	
	$mode = isset($url[1]) ? $url[1] : '' ; 
	
	 switch($mode){ 
	  case "catalogs":
		  viewcaTsub();
		  break;
	  default:
		 // viewCate(); 
		include "maincontent.htm";
		include "main.htm";	 
		include "mainbottom.htm";
		  break; 
	 } 

function viewcaTsub(){
	global $db,$url,$template_sub_cat,$template,$site_base_href,$base_url,$ids ;
	
   $id=$url[2];	 
  
  //$sql="select * from vb_category where cat_active=1 and cat_Level!=1 and catCount>0 order by cat_Name";	
   $sql="select * from vb_category where cat_active=1 and cat_Level!=1 and catCount>0";
   if(!$result=$db->sql_query($sql)){
		message_die("Couldn't run the sql query!!!", "", __LINE__, __FILE__, $sql);
	}

	$cat_count=$db->sql_numrows($result);
	$cat_data=$db->sql_fetchrowset($result);

	//$numrow= ceil($cat_count/2);
	$i=0;
	$template->assign_block_vars("catrow", array());		
	while($i<$cat_count){	  		
			//for($j=0;$j<$numrow;$j++){ //phan cot (hix b? uong qua')		
			//link ket vo sub m  b? di thi?t het noi' noi?				
			//'<a href="'.$site_base_href."/".$base_url.'/catalogs/'.$cat_data[$i]["catID"].'/index.html" class="CAT">'. $cat_data[$i]['cat_Name'].'</a>',
				if($i<$cat_count){				 
					if(isset($cat_data[$i]["cat_Sub"])&&($cat_data[$i]["cat_Sub"]==$id)){
						$sub=0;
						if($cat_data[$i]["cat_Level"]<4){
							$sub=checkSubCat($cat_data,$cat_data[$i]["catID"]);
						}						
						$template->assign_block_vars('catrow.catcol1',array(			
							'subTitle'	=> !$sub  ? '<span class="co11"> &raquo;</span> <a href="'.$site_base_href."/".$base_url.'?/manufacturers/'.$cat_data[$i]["catID"].'/'.ereg_replace(" ","_",$cat_data[$i]["cat_Name"]).'.html?ids='.$ids.'&lang=us" class="CAT">'. $cat_data[$i]['cat_Name'].'</a>': ' <span class="co11"> &raquo;</span> '.$cat_data[$i]['cat_Name'],
							'catID' => $site_base_href."/".$base_url ."?/products/manufacturers/".$cat_data[$i]["catID"]."/".ereg_replace(" ","_",$cat_data[$i]["cat_Name"]) .'.html',
							'numproduct'  => !empty($cat_data[$i]["catCount"]) ? " (".$cat_data[$i]["catCount"].")" : ''
						));						 
						if($sub){
						 	$jj=0;
							 while($jj<$cat_count){
								if(isset($cat_data[$jj]["cat_Sub"])&&($cat_data[$i]["catID"]==$cat_data[$jj]["cat_Sub"])){									
									$sub=0;
									if($cat_data[$jj]["cat_Level"]<4){
										$sub=checkSubCat($cat_data,$cat_data[$jj]["catID"]);
									}										
									 //'&nbsp;&#8226; <a href="'.$site_base_href."/".$base_url.'/catalogs/'.$cat_data[$jj]["catID"].'/'.ereg_replace(" ","_",$cat_data[$jj]["cat_Name"]).'.html?ids='.$ids.'&lang=us" class="CAT">'. $cat_data[$jj]['cat_Name'].$proc.'</a>',
									 $proc=!empty($cat_data[$jj]["catCount"]) ? " (".$cat_data[$jj]["catCount"].")" : '';
									$template->assign_block_vars('catrow.catcol1.catcol2',array(
									'subTitle'	=> !$sub  ? '&nbsp;&#8226; <a href="'.$site_base_href."/".$base_url.'?/manufacturers/'.$cat_data[$jj]["catID"].'/'.ereg_replace(" ","_",$cat_data[$jj]["cat_Name"]).'.html?ids='.$ids.'&lang=us" class="CAT">'. $cat_data[$jj]['cat_Name'].$proc.'</a>': '&nbsp;&#8226; '. $cat_data[$jj]['cat_Name'].$proc,						 															  
									));					
									
									if($sub){
										 $k=0 ;
										 while($k <$cat_count){
											if($cat_data[$jj]["catID"]==$cat_data[$k]["cat_Sub"]){									
											$proc=!empty($cat_data[$k]["catCount"]) ? " (". $cat_data[$k]["catCount"]. ")" :'';			
												$template->assign_block_vars('catrow.catcol1.catcol2.catcol3',array(
													'subTitle'		=> '&nbsp;-&nbsp;<a href="'.$site_base_href."/".$base_url.'?/manufacturers/'.$cat_data[$k]["catID"].'/'.ereg_replace(" ","_",$cat_data[$k]["cat_Name"]).'.html1?ids='.$ids.'&lang=us" class="CAT">'.$cat_data[$k]['cat_Name'].'</a>'.$proc
												));		
												unset($cat_data[$k]);													
											}
											$k++ ;			
										 }	
									 }	
									unset($cat_data[$jj]);																
								}
								$jj++ ;
							  } //Ew jj
						 }
					unset($cat_data[$i]);					
					 }
				 }		
    			$i++;				 	
			//} 				
    }
	 unset($cat_data);
	 
	$template->assign_vars(array(
	 	'url'	=>$site_base_href,
		'subcat' =>getSubTitle($id),
		'maintitle'	=>getSubTitle($id,1).' | YellowPages.vn' ,
	)); 
	 
	$template->set_filenames(array('body'=> $template_sub_cat));
	$template->pparse('body');
	$template->destroy();
	$cat_data=array();	
	$lead_data=array();	
}
?>